<template>
    <view class="bg-content">
        <u-search placeholder="请输入商城名称" shape="square" v-model="searchKeyword" @search="onSearch" @custom="onSearch"></u-search>
        <u-cell-group>
            <u-cell-item v-for="(item, index) of tbCommunityList" :key="item.id" :title="item.name" :arrow="true"
                         @click="select(item)"></u-cell-item>
        </u-cell-group>

        <div style="padding-top: 10px; padding-bottom: 10px;">
            <u-loadmore :status="pagination.status" bg-color="#eeeeee"/>
        </div>
    </view>
</template>

<script>

    import {TbCommunityService} from "../../../../../../dev/services/tb-community.service";
    import {CommonUtil} from "../../../../../../dev/core/utils/common.util";

    export default {
        data() {
            return {
                searchKeyword: '',
                tbCommunityList: []
            }
        },
        onReady() {
            const _self = this;
            this.doRefresh(this.tbCommunityList);
        },
        methods: {
            onSearch(event) {
                this.searchKeyword = CommonUtil.trim(this.searchKeyword);
                this.doRefresh(this.tbCommunityList);
            },
            select(item) {
                const _self = this;
                if (item.type == null || item.type === "0" || item.type === "1") {
                    _self.objParams.communityId = item.id;
                    _self.objParams.communityName = item.name;
                    CommonUtil.toastNavigateBack();
                } else {
                    CommonUtil.alert({
                        title: '提示！',
                        content: `该商城【${item.name}】注册后需要管理员审核通过后才能登录。`,
                        showCancel: true, // 是否显示取消按钮
                        success: function (res) {
                            if (res.cancel) { // 点击取消,默认隐藏弹框
                            } else { // 点击确定
                                _self.objParams.communityId = item.id;
                                _self.objParams.communityName = item.name;
                                CommonUtil.toastNavigateBack();
                            }
                        }
                    });
                }
            },
            /**
             * 加载更多数据中
             * @param infiniteScroll
             */
            doInfinite(infiniteScroll) {
                const _self = this;
                new TbCommunityService().findTbCommunityList({
                    name: _self.searchKeyword,
                    provinceName: _self.objParams.provinceName,
                    cityName: _self.objParams.cityName,
                    areaName: _self.objParams.areaName,
                    status: '1',
                    deleted: 0
                }).then(result => {
                    _self.tbCommunityList = result;
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
</style>
